/*
 * @Author: 0x9DEFA478
 * @Date: 2025-06-22 16:44:31
 * @LastEditTime: 2025-09-19 21:47:29
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * 
 */
#ifndef hHMakeDecode_HPP_
#define hHMakeDecode_HPP_
#include <string>
#include <functional>
#include "H_Pointer.hpp"
#include "Tree/H_Tree_AVL.hpp"
#include "hmkdecode.hpp"
#include "HMakeTargetConfig.hpp"


namespace HMake{

  class ValuePool;


  class Decoder{

    public:

      Decoder(const std::string& cwd,const std::string& targetName)noexcept;
      ~Decoder()noexcept;

      Decoder(Decoder&)=delete;
      Decoder(Decoder&&)=delete;
      
      void Load(const std::string& path);

      H::Tree::AVL<std::string,TargetConfig::Pointer> GetTargetConfigCollection(){return TargetConfigCollection;}

    private:
      using Args_t=std::vector<Value::Pointer>;

      void ExecuteLine(const HMake::Expression::Pointer& LinePointer,const std::string& path);
      
      Value::Pointer ExecuteFunction(const std::string& functionName,const Args_t& args,int line,int pos,const std::string& path);
      
      void ResetValuePool();


      Value::Pointer Function_if(const Args_t& args,int line,int pos,const std::string& path);
      Value::Pointer Function_eq(const Args_t& args,int line,int pos,const std::string& path);
      Value::Pointer Function_ne(const Args_t& args,int line,int pos,const std::string& path);
      Value::Pointer Function_not(const Args_t& args,int line,int pos,const std::string& path);
      Value::Pointer Function_and(const Args_t& args,int line,int pos,const std::string& path);
      Value::Pointer Function_or(const Args_t& args,int line,int pos,const std::string& path);
      
      Value::Pointer Function_IsSuffix(const Args_t& args,int line,int pos,const std::string& path);
      Value::Pointer Function_GetLine(const Args_t& args,int line,int pos,const std::string& path);
      Value::Pointer Function_PopLine(const Args_t& args,int line,int pos,const std::string& path);
      Value::Pointer Function_ArrayToString(const Args_t& args,int line,int pos,const std::string& path);

      Value::Pointer Function_ClearContext(const Args_t& args,int line,int pos,const std::string& path);
      Value::Pointer Function_SetTargetConfig(const Args_t& args,int line,int pos,const std::string& path);
      Value::Pointer Function_DirectoryRecursive(const Args_t& args,int line,int pos,const std::string& path);
      
      Value::Pointer FileFromDirectory(const Args_t& args,int line,int pos,const std::string& path,bool IsRecursive);
      Value::Pointer Function_FileFromDirectory(const Args_t& args,int line,int pos,const std::string& path);
      Value::Pointer Function_FileFromDirectoryRecursive(const Args_t& args,int line,int pos,const std::string& path);
      Value::Pointer Function_Print(const Args_t& args,int line,int pos,const std::string& path);

      
    private:
      const std::string cwd;
      const std::string targetName;
      ValuePool* valuePool;
      H::Tree::AVL<std::string,TargetConfig::Pointer> TargetConfigCollection;

      using FunctionType=std::function<Value::Pointer (const Args_t&,int,int,const std::string&)>;
      H::Tree::AVL<std::string,FunctionType> functionMap;

  };


}


#endif //hHMakeDecode_HPP_
